package service

import (
	"github.com/kardianos/service"
	"miao-va-host/global"
	"os"
	"runtime"
)

const (
	Name        = "miaoClient"
	DisplayName = "miao client display" // Display name, spaces allowed.
	Description = "miao client description"
)

// New creates and configures a new service.
func New() (service.Service, error) {
	config := &service.Config{
		Name:        Name,
		DisplayName: DisplayName,
		Description: Description,
		Arguments:   []string{},
	}

	switch runtime.GOOS {
	case "darwin":
		config.Option = service.KeyValue{
			"KeepAlive":   true,
			"RunAtLoad":   true,
			"UserService": os.Getuid() != 0,
		}
	case "windows":
		if global.Conf.AccountInfo.UserName != "" {
			config.UserName = global.Conf.AccountInfo.UserName
			config.Option = service.KeyValue{
				"Password": global.Conf.AccountInfo.Password,
			}
		}
	}
	m := new(manager)
	return service.New(m, config)
}
